/*
 * bsp_thread.h
 *
 * Copyright (C) 2011 - Dr.NP
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * @version bsp_thread.h 1.0.0
 * @package libbspcore
 * @author Dr.NP <np@bsgroup.org>
 * @update 03/21/2011
 */

#ifndef BSP_THREAD_H

#define BSP_THREAD_H                            1

#include "config.h"
#include <pthread.h>
// Definations
#define MAX_THREADS                             1024

#define DISPATCH_ADD_CLIENT                     0x1
#define DISPATCH_ADD_TIMER                      0x2
#define DISPATCH_ADD_CONNECTOR                  0x3
#define DISPATCH_ADD_LUASTATE                   0x4
#define DISPATCH_DEL                            0xF

// Macros

// Structs
// Structs
struct worker_t
{
    int id;
    pthread_t tid;
    pthread_attr_t attr;
    int thread_type;
    int epoll_fd;
#ifdef HAVE_EVENTFD
    int notify_event_fd;
#else
    int notify_recv_fd;
    int notify_send_fd;
#endif
};

// Functions
int thread_init(int);

struct worker_t * get_worker(int);
void dispatch_timer(int);
void dispatch_client(int);
void dispatch_connector(int);
void dispatch_luastate(int);

void remove_from_worker(int, int);
void touch_worker(int);

#endif  /* bsp_thread.h */
